﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Sasa.QualityTools.CodeAnalysis.Core.Models;
using System.Collections.ObjectModel;

namespace Sasa.QualityTools.CodeAnalysis.FxCopIntegrator.ViewModels.Configurations
{
    public class GenericConfigurationViewModel : ViewModelBase
    {
        public event EventHandler BrowseRuleSetRequired;


        private CodeAnalysisConfiguration model;


        public bool OverrideEnableSearchGac
        {
            get
            {
                return model.OverrideEnableSearchGac;
            }
            set
            {
                model.OverrideEnableSearchGac = value;
                OnPropertyChanged("OverrideEnableSearchGac");
            }
        }

        public bool OverrideIgnoreGeneratedCode
        {
            get
            {
                return model.OverrideIgnoreGeneratedCode;
            }
            set
            {
                model.OverrideIgnoreGeneratedCode = value;
                OnPropertyChanged("OverrideIgnoreGeneratedCode");
            }
        }

        public bool OverrideTimeout
        {
            get
            {
                return model.OverrideTimeout;
            }
            set
            {
                model.OverrideTimeout = value;
                OnPropertyChanged("OverrideTimeout");
            }
        }

        public bool OverrideRuleSet
        {
            get
            {
                return model.OverrideRuleSet;
            }
            set
            {
                model.OverrideRuleSet = value;
                OnPropertyChanged("OverrideRuleSet");
            }
        }

        public bool EnableSearchGac
        {
            get
            {
                return model.EnableSearchGac;
            }
            set
            {
                model.EnableSearchGac = value;
                OnPropertyChanged("EnableSearchGac");
            }
        }

        public bool IgnoreGeneratedCode
        {
            get
            {
                return model.IgnoreGeneratedCode;
            }
            set
            {
                model.IgnoreGeneratedCode = value;
                OnPropertyChanged("IgnoreGeneratedCode");
            }
        }

        public double Timeout
        {
            get
            {
                return model.Timeout;
            }
            set
            {
                model.Timeout = value;
                OnPropertyChanged("Timeout");
            }
        }

        public static double MinimumTimeout
        {
            get
            {
                return 0;
            }
        }

        public static double MaximumTimeout
        {
            get
            {
                return 180;
            }
        }

        public string RuleSet
        {
            get
            {
                return model.RuleSet;
            }
            set
            {
                model.RuleSet = value;
                OnPropertyChanged("RuleSet");
            }
        }

        public ICollection<RuleSetViewModel> RuleSets { get; private set; }

        public RelayCommand BrowseRuleSetCommand { get; private set; }


        public GenericConfigurationViewModel(CodeAnalysisConfiguration model)
        {
            this.model = model;
            RuleSets = new ObservableCollection<RuleSetViewModel>();
            BrowseRuleSetCommand = new RelayCommand(o => BrowseRuleSet());
        }

        
        public void BrowseRuleSet()
        {
            if (BrowseRuleSetRequired != null)
            {
                BrowseRuleSetRequired(this, EventArgs.Empty);
            }
        }
    }
}
